In [1]:
import shopify
tool - 1 Remove app
API Key f402c6ff49515572dc9e54a179b17c1e
Password    2d2b63c69ffd14d0e3905b0ed33f3332
Shared Secret   542b6edb1ce5e2850a9c112c1f906272
URL Format  https://apikey:password@hostname/admin/resource.xml
Example URL https://f402c6ff49515572dc9e54a179b17c1e:2d2b63c69ffd14d0e3905b0ed33f3332@tomfoolery-3.myshopify.com/admin/orders.xml

In [7]:
SHOP_NAME = "tomfoolery-3"
API_PASSWORD = "2d2b63c69ffd14d0e3905b0ed33f3332"
session = shopify.Session(SHOP_NAME)
session.token = API_PASSWORD
shopify.ShopifyResource.activate_session(session)

In [8]:
products = shopify.Product.find()

In [9]:
products


Out[9]:
[product(159734703), product(159735013), product(159734335)]

In [17]:
products[0].attributes


Out[17]:
{'body_html': 'Bang. Exclaim.',
 'created_at': datetime.datetime(2013, 9, 23, 15, 46, 28, tzinfo=tzoffset(None, -14400)),
 'handle': 'product',
 'id': 159734703,
 'image': image(319187389),
 'images': [image(319187389)],
 'options': [option(191882525)],
 'product_type': 'Langauge Tools',
 'published_at': datetime.datetime(2013, 9, 23, 15, 43, 36, tzinfo=tzoffset(None, -14400)),
 'published_scope': 'global',
 'tags': None,
 'template_suffix': None,
 'title': '!',
 'updated_at': datetime.datetime(2013, 9, 23, 16, 32, 55, tzinfo=tzoffset(None, -14400)),
 'variants': [variant(365973457)],
 'vendor': 'English'}

In [23]:
i = products[0].images[0]

In [25]:
i.get_id()


Out[25]:
319187389

In [29]:
from IPython.core.display import Image 
Image(url=products[0].images[0].src)


Out[29]:

In [34]:
#instantiate a new product
new_product = shopify.Product()
print new_product.id  # Only exists in memory for now


None

In [35]:
# add main meta info
new_product.product_type = "punctuation"
new_product.body_html = "<strong>!?!?!</strong>"
new_product.title = "Surprised"

In [36]:
# create product variants
variant1 = shopify.Variant()
variant2 = shopify.Variant(dict(price="20.00", option1="Second")) # attributes can be set at creation
new_product.variants = [variant1, variant2]

In [38]:
new_product.vendor = "Burton"
new_product.save()  # Sends request to Shopify
new_product.id


Out[38]:
160406253

In [39]:
# or create a product with create
product = shopify.Product.create(dict(product_type="Snowboard", body_html="<strong>Good snowboard!</strong>", title="Burton Custom Freestlye 151", tags="Barnes & Noble, John's Fav, \"Big Air\"", vendor="Burton"))
product.id  # The create method already called save


Out[39]:
160406501

In [44]:
# Error Handling
bad_product = shopify.Product.create(dict(product_type=''))
bad_product.save()


Out[44]:
False

In [45]:
bad_product.errors.full_messages()


Out[45]:
["Title can't be blank",
 "Product type can't be blank",
 'Product type is too short (minimum is 2 characters)']

In [ ]: